home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / gprim / geom / boundsphere.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-15  |  887 b   |  37 lines

  1. #include "hpoint3.h"
  2. #include "geomclass.h"
  3. #include "geom.h"
  4. #include "bbox.h"
  5. #include "create.h"
  6.  
  7. /* Take this out once the create flags are all in the right place */
  8. #include "sphereP.h"
  9.  
  10. Geom *
  11. GeomBoundSphere(geom, T, space)
  12.      Geom *geom;
  13.      Transform T;
  14.      int space;
  15. {
  16.   Geom *bbox, *sphere;
  17.   HPoint3 minmax[2];
  18.  
  19.   if (geom && geom->Class->boundsphere) {
  20.     return (*geom->Class->boundsphere) (geom, T==NULL ? TM_IDENTITY : T,
  21.                     space);
  22.   }
  23.  
  24.   bbox = GeomBound(geom, T);
  25.   if (bbox == NULL) return NULL;
  26.   BBoxMinMax((BBox *)bbox, &minmax[0], &minmax[1]);
  27.   GeomDelete(bbox);
  28.   HPt3Normalize(&minmax[0], &minmax[0]);
  29.   HPt3Normalize(&minmax[1], &minmax[1]);
  30.  
  31.   sphere = GeomCreate("sphere", CR_ENCOMPASS_POINTS, minmax,
  32.               CR_NENCOMPASS_POINTS, 2, CR_SPACE, space,
  33.               CR_END);
  34.   if (sphere != NULL && T != NULL) GeomTransform(sphere, T);
  35.   return sphere;
  36. }
  37.